# 计算 一元二次方程 结果 ax²+bx+c=0 （a≠0）

import math
a = int(input("Enter value of a: "))
b = int(input("Enter value of b: "))
c = int(input("Enter value of b: "))
if a == 0:
    print("a can not be zero!")
else:
    # 初始化 bx c 前面的符号为 +
    operation_b = '+'
    operation_c = '+'
    if b < 0:
        operation_b = '-'   # 如果b小于零，设置为 -
    if c < 0:
        operation_c = '-'   # 如果c小于零，设置为 -

    # 判断 a b 要不要省略
    if math.fabs(a) == 1:
        a_str = ''
    else:
        a_str = str(a)
    if math.fabs(b) == 1:
        b_str = ''
    else:
        b_str = str(int(math.fabs(b)))
    print("equation is: {:s}x²{:s}{:s}x{:s}{:s}=0".format(a_str, operation_b, b_str, operation_c, str(int(math.fabs(c)))))

    # 开始计算 x=[-b±√(b²-4ac)]/2a
    # ① 计算 (b²-4ac)
    d = b * b - 4 * a * c
    if d < 0:
        print("error to calculate")
    else:
        root1 = (-b + math.sqrt(d)) / (2 * a)
        root2 = (-b - math.sqrt(d)) / (2 * a)
        print("Root 1 = ", root1)
        print("Root 2 = ", root2)
